package com.sx.micowell.module.trainplan

import android.view.View
import android.widget.ImageView
import android.widget.ProgressBar
import androidx.constraintlayout.widget.ConstraintLayout
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.mvvm.until.LogUtils

import com.miloyu.modelnet.response.TrainListVO
import com.miloyu.modelnet.response.getUrl
import com.sx.micowell.R





/**
 * @Author: YY
 * @Time: 2021/8/28
 * @Describe TODO
 */
class TrainPlanListAdapter(planSelectData: MutableList<TrainListVO>?=null) :
                            BaseQuickAdapter<TrainListVO, BaseViewHolder>(R.layout.item_plan_list) {

    var selectData: MutableList<TrainListVO>?=null
    init {
        this.selectData=planSelectData
    }
    var showDeleteView:Boolean=true

    override fun convert(holder: BaseViewHolder, item: TrainListVO) {
        Glide.with(context).load(item.icon.getUrl()).into(holder.getView(R.id.image_title))
        holder.setText(R.id.tv_title, "${item.title}训练")
        holder.setText(R.id.tv_content, "${item.startTime}-${item.endTime}" +
                "·${getWeek(item.params.week.toInt())}·${item.duration}分钟")

        if (item.duration != 0) {
            val dd: Int = ((item.durationNow.toDouble() / item.duration.toDouble()) * 100).toInt()
            holder.setText(R.id.tv_rate, "${dd}%")

            val progressBar: ProgressBar = holder.getView<View>(R.id.progress_plan) as ProgressBar
            progressBar.progress = dd
        }

        holder.getView<ImageView>(R.id.image_delete).visibility=if(showDeleteView) View.VISIBLE else View.GONE

        this.selectData?.let {
            holder.getView<ConstraintLayout>(R.id.item_plan_layout).isSelected=it.contains(item)
        }

    }

    private fun getWeek(weekValue: Int): String {
        return when (weekValue) {
            1 -> "周日"
            2 -> "周一"
            3 -> "周二"
            4 -> "周三"
            5 -> "周四"
            6 -> "周五"
            7 -> "周六"
            else -> {
                ""
            }
        }
    }
}